package cn.inno.index;

import cn.inno.controller.BaseController;
import cn.inno.entitys.SysAdmin;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 导航控制器
 *
 * @author LeungZengJian
 */
@Controller
public class IndexController extends BaseController {

    @Autowired
    private IndexService asideService;

    @RequestMapping(value = {"/", "/index", "/index.*"})
    public String list(Model model) {
        JSONObject jsonObject = new JSONObject();
        try {
            SysAdmin sysAdmin = (SysAdmin) this.getAuth();
            jsonObject = this.asideService.list(sysAdmin.getAdminId());
            model.addAttribute(KEY_DATA, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
            return "login";
        }
        return "index";
    }

    @RequestMapping("/**/*.html")
    public String toPage(HttpServletRequest request) {
        return request.getServletPath().substring(0, request.getServletPath().length() - 5);
    }


}
